Moving a Cube from a GUI texture on iOS [on hold]

Posted by London2423 on Game Development See other posts from Game Development or by London2423
Published on 2014-06-11T10:13:21Z Indexed on 2014/06/11 15:44 UTC
Read the original article Hit count: 285

Filed under:
|
|
|
|

I really hope someone can help me in this since I am working already two days but without any result.

What I' am trying to achieve in this instance is to move a GameObject when a GUI Texture is touch on a Iphone. The GameObject to be moved is named Cube. The Cube has a Script named "Left" that supposedly when is "call it " from the GUITexture the Cube should move left.

I hope is clear: I want to "activated" the script in the Game Object from the Guitexture. I try to use send message but without any joy as well so I am using GetComponent.

This is the script "inside" the GUITexture using Unity and C#

    //script inside the gameobject cube so it can move left when call it from the GUItexture

    void Awake()

{ 
    left = Cube.GetComponent<Left>().enable = true;
}

    void Start() 
{ 
    Cube = GameObject.Find ("Cube"); 
}

    void Update ()
{

        //loop through all the touches on the screeen 

            for(int i = 0 ; i < Input.touchCount; i++)
            {
                //execute this code for current touch (i) on the screen 

                if(this.guiTexture.HitTest(Input.GetTouch(i).position))
                {
                    //if current hits our guiTecture, run this code
                    if(Input.GetTouch (i).phase == TouchPhase.Began)

                        //move the cube object


                        Cube.GetComponent<Left> ();


                }

                    if(Input.GetTouch (i).phase == TouchPhase.Ended)

                     {      

                        return; 
                     }
                        if(Input.GetTouch(i).phase == TouchPhase.Stationary);


                          //if current finger is stationary  run this code
                     {      
                           Cube.GetComponent<Left> ();
                     }

         }

    }
}

}

This is the script inside the GameObject named "Cube" that is activated from the Gui Texture and when is activated from the GUITexture should allow the cube to move left

public class Left : MonoBehaviour {

// Use this for initialization
void Start ()
{


}

// Update is called once per frame



   void OnMousedown ()
    {

             transform.position += Vector3.left * Time.deltaTime;

} }

Before write here I search all documentation, tutorial videos, forums but I still don't understand where is my mistake. May please someone help me

Thanks

CL

© Game Development or respective owner

Related posts about c#

Related posts about unity